package com.cyjf.biz.impl;

import com.cyjf.biz.service.UserService;

import com.cyjf.dbview.mapper.UserPOMapper;
import com.cyjf.dbview.model.UserPO;
import com.cyjf.util.CreateMD5;
import com.cyjf.util.ErrorContent;
import com.cyjf.util.ResultVO;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import sun.misc.BASE64Encoder;

import javax.annotation.Resource;

import java.security.MessageDigest;
import java.util.List;

@Service("userService")
@Slf4j
public class UserServiceImpl implements UserService {

    @Resource
    private UserPOMapper userPOMapper;

    @Override
    @SneakyThrows
    public ResultVO  checkUserLogin(UserPO userPO) {
        ResultVO< List<UserPO>> resultVO = new ResultVO();
        MessageDigest md5=MessageDigest.getInstance("MD5");
        BASE64Encoder base64en = new BASE64Encoder();
        //加密后的字符串
        String newPwd= CreateMD5.getMd5(userPO.getLoginPwd());

        userPO.setLoginPwd(newPwd);
        List<UserPO> list = userPOMapper.select(userPO);

        if (list.size()==0) {

            log.error(ErrorContent.QIANHAI_INTERFACE_NO_RESULT_MESSAGE +",userName为："+userPO.getLoginName());
            resultVO.setMessage(ErrorContent.USER_OR_PASSWD_ERROR);
        }else
            resultVO.setMessage("登录成功");

        return resultVO;
    }



}
